package com.dense.kuiniu.floatcabinet.mvp.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * @author Administrator
 * @date 2020/9/29
 */
public class BoxItem extends View {
    Paint paint;
    PaintFlagsDrawFilter flagsDrawFilter;
    Paint textPaint;
    private String number;

    public BoxItem(Context context) {
        this(context, null);
    }

    public BoxItem(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BoxItem(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setDither(true);
        paint.setFilterBitmap(true);
        flagsDrawFilter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);

        textPaint = new Paint();
        textPaint.setColor(Color.parseColor("#4D81FF"));
        textPaint.setTextSize(30);
    }

    @Override
    public void dispatchDraw(Canvas canvas) {
        canvas.setDrawFilter(flagsDrawFilter);
    }

    public void setNumber(String number) {
        this.number = number;
        invalidate();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (number != null) {
            canvas.drawText(this.number, 60, 60, textPaint);
        }
    }


}